<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>运费</title>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <input type="hidden" id="type" name="type" value="2">
                        <div class="form-group">
                            <label class="control-label col-sm-1">国家:</label>
                            <div class="col-sm-2">
                                <select id="createPlanCountry" name="createPlanCountry" class="form-control">
                                    <option value="">全部</option>
                                    <%for(var dict in country){%>
                                    <option value="${dict.detailName}">${dict.detailName}</option>
                                    <%}%>
                                </select>
                            </div>



                            <label class="control-label col-sm-1">实际装柜日期:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createPlanDateBegin" name="createPlanDateBegin" placeholder="请选择开始时间" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">实际装柜日期:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createPlanDateEnd" name="createPlanDateEnd" placeholder="请选择结束时间" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-1">运输方式:</label>
                            <div class="col-sm-2">
                                <select id="createPlanCabinetName" name="createPlanCabinetName" class="form-control">
                                    <option value="">全部</option>
                                    <%for(var dict in cabinet){%>
                                    <option value="${dict.cabinetName}">${dict.cabinetName}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">柜号:</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="createPlanNo" name="createPlanNo">
                            </div>
                            <a class="search-btn btn  btn-success" >查询</a>
                            <!--<a class="export-btn btn btn-success"><i class="glyphicon glyphicon-list-alt" aria-hidden="true"></i> 导出当前数据</a>-->
                        </div>
                    </form>
                </div>
            </div>
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <button  class="layui-btn layui-btn-sm import-btn" style="margin-left: 10px"  id="import-btn"  name="import-btn">
                    <i class="layui-icon"></i>导入海运费关税信息
                </button>
                <button  class="export-btn layui-btn  layui-btn-sm" >
                    <i class="fa fa-download" aria-hidden="true"></i> 导出表头数据
                </button>
                <button  class="export-detail-btn layui-btn  layui-btn-sm" >
                    <i class="fa fa-download" aria-hidden="true"></i> 导出明细数据
                </button>
                <button  class="layui-btn  layui-btn-sm" >
                    <i class="fa fa-download"></i>
                    <a href="/excel/海运费信息.xlsx" style="color: white" download>模板下载</a>
                </button>
            </div>
        </div>
    </div>
</div>

<!-- START 数据表格 -->
<table id="freightTable"
       data-toolbar="#toolbar"
       data-pagination="true"
       data-resizable="true"
       data-side-pagination="server"
       data-url="/sea/physical/customs/findByCnd.do"
       data-page-size="15"
       class="table table-striped table-hover"
>
</table>

<div id="layer_window" style="display: none;overflow-x: hidden">
    <div class="form-group">
        <label class="control-label col-sm-2" style="margin-top: 15px;padding-top: 6px;">实际运费</label>
        <div class="col-sm-9" style="margin-top: 15px;width: 300px;">
            <input type="text" class="form-control" id="dispatchActFreight" name="dispatchActFreight" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')">
        </div>
    </div>
</div>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,chosen,chosen-demo,layui'}){}%>
<script>
    laydate.render({
        elem: '#createPlanDateBegin' //指定元素
        ,trigger: 'click'
    });
    laydate.render({
        elem: '#createPlanDateEnd' //指定元素
        ,trigger: 'click'
    });
    var $freightTable = $('#freightTable');

    $(function () {

        // START 表格配置
        $freightTable.bootstrapTable({
            queryParams : function (params) {
                //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                var temp = {
                    type: 2,
                    limit: params.limit,     //页面大小
                    offset: params.offset    //页码
                };
                return temp;
            },
            pageSize:10,
            detailView: true,
            columns: [
                {
                    title: '国家',
                    field: 'createPlanCountry',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜型',
                    field: 'createPlanCabinetName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '运输方式',
                    field: 'createPlanTransport',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '目的仓库',
                    field: 'despatchStoreName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '货代公司',
                    field: 'despatchSupplier',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '开船日期',
                    field: 'boatDate',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '箱数',
                    field: 'createPlanBox',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '毛重',
                    field: 'createWeightTotal',
                    align: 'center',
                    valign: 'middle'
                },

                {
                    title: '体积',
                    field: 'createPlanVolume',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '预估运费',
                    field: 'despatchFreight',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '预估关税',
                    field: 'createCustomTax',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '预估关税(rmb)',
                    field: 'createCustomTaxCny',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '实际运费',
                    field: 'despatchRealFreight',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '实际关税',
                    field: 'createRealTax',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){

                // 修改按钮
                $('.btn-freight-edit').on('click',function () {
                    // editActFreight($(this).attr('data-val'),$(this).attr('data-name'));
                    var id=$(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        zIndex:1,
                        content: ['/sea/physical/report/editFreightPage.do?id='+id, 'yes']
                    });
                });

                $('.add-freight-btn').on('click',function () {
                    var createId=$(this).attr('data-val');
                    layer.open({
                        type: 2,
                        area: ['500px','600px'],
                        skin: 'layer-ext-espresso',
                        zIndex:1,
                        content: ['/sea/physical/createFreight/freightMain.do?createId='+createId, 'yes']
                    });
                });

                // 下推至财务
                $('.btn-freight-finance').on('click',function () {
                    var id=$(this).attr('data-val');
                    $.ajax({
                        type :'post',
                        url :'/sea/finance/save',
                        data : {'createId':id,'financeType':2},
                        success:function (data) {
                            if( data.ok ){
                                layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                                    $freightTable.bootstrapTable('refresh');
                                    layer.closeAll(); //关闭弹窗
                                });
                            }else{
                                layer.closeAll(); //关闭弹窗
                                layer.msg(data.msg,{icon: 0,time:5000,shade: [0.8, '#393D49']});
                            }
                        }
                    })
                })
            },onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });

        //初始化子表格(无线循环)
        var cur_table ='';
        function InitSubTable (index, row, $detail) {
            var createId = row.createId;
            cur_table = $detail.html('<table id="detailTable"></table>').find('table');
            $(cur_table).bootstrapTable({
                url: '/sea/physical/createFreight/findByCreateId',
                method: 'get',
                clickToSelect: true,
                queryParams: { createId: createId},
                //height: 500,
                detailView: false,//父子表
                uniqueId: "id",
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    {
                        field: 'createSupplier',
                        title: '供应商'
                    },
                    {
                        field: 'createMoneyType',
                        title: '币种'
                    },
                    {
                        field: 'createMoney',
                        title: '金额'
                    },
                    {
                        field: 'createPay',
                        title: '付款状态',
                        formatter:function (v, r) {
                            if(v==0){
                                return '未付款';
                            }else{
                                return '已付款';
                            }
                        }
                    },
                    {
                        field: 'flag',
                        title: '类型',
                        formatter:function (v, r) {
                            if(v==0){
                                return '运费';
                            }else if(v==1){
                                return '关税';
                            }
                            else if(v==2){
                                return '头程';
                            }
                            else if(v==3){
                                return '海运';
                            }
                            else if(v==4){
                                return '尾程';
                            }
                        }
                    },
                    {
                        field: 'createPayType',
                        title: '付款方式'
                    },
                    {
                        field: 'createRemark',
                        title: '备注'
                    },
                    {
                        title: '操作',
                        field: 'operate',
                        align: 'center',
                        valign: 'middle',
                        formatter: optFormatter1
                    }],
                onLoadSuccess : function(){
                    $('.del-btn').on('click',function(){
                        var id = $(this).attr('data-val');
                        layer.confirm('确定要删除当前？', {
                            btn: ['确定','取消'],title:'提示'
                        }, function(){
                            $.post('/sea/physical/createFreight/delete.do',{id: id},function(data){
                                if( data.ok ){
                                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                        //刷新页面
                                        $freightTable.bootstrapTable('refresh');
                                    });
                                }else{
                                    layer.msg(data.msg,{icon: 0,time: 1500});
                                }
                            });
                        });
                    });
                }
            });
        };

        // 条件查询
        $('.search-btn').on('click',function () {
            $freightTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/physical/customs/findByCnd.do?'+$('#search-form').serialize() });
        });
        $(".export-btn").click(function () {
            window.location.href='/sea/physical/customs/exportFreight.do?'+$('#search-form').serialize();
        });
        $(".export-detail-btn").click(function () {
            window.location.href='/sea/physical/createFreight/exportDetail.do?'+$('#search-form').serialize();
        });



        //操作菜单
        function optFormatter(value,row){
            var content ='';
            content += '<button class="add-freight-btn btn btn-xs btn-success" data-val="'+row.createId+'" title="新增"><i class="fa fa-plus"></i>  </button>';
            return content;
        }

        //操作菜单
        function optFormatter1(value,row){
            var content ='';
            content += '<button class="del-btn btn btn-xs btn-danger" data-val="'+row.id+'" title="删除"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>  </button>';
            return content;
        }

        layui.use('upload', function(){
            var upload = layui.upload;
            upload.render({
                elem: '#import-btn', //绑定元素,
                accept:'file',
                url: '/sea/physical/createFreight/import/', //上传接口
                data:{"productMember":$("#productMember").val()},
                before:function () {
                    layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                }
                ,done: function(data){
                    if( data.ok ){
                        layer.msg(data.msg,{icon: 1,time: 1500},function(){
                            //刷新页面
                            $freightTable.bootstrapTable('refresh');
                            layer.closeAll();
                        });
                    }else{
                        layer.msg(data.msg,{icon: 0,time: 5000},function () {
                            layer.closeAll();
                        });

                    }
                }
                ,error: function(){
                    //请求异常回调
                    layer.closeAll();
                }
            });
        });
    });
</script>
</body>
</html>